﻿using System;

namespace Program14
{
    
    public enum Gender//定义枚举
    {
            男,
            女,
            其他
    }
    public enum QQState//定义枚举
    {
        //枚举的成员可以定义它们的整型值
        online=1,
        offine=0,
        leave=2,
        busy=3,
        Qme=4
    }

    class Program
    {   
        static void Main(string[] args)
        {

            #region 将枚举类型转换成Int
            //QQState state = QQState.online;
            //int n = (int)state;
            //Console.WriteLine("QQ在线枚举成员的值：" + n);
            //Console.WriteLine("QQ离线枚举成员的值：" + (int)QQState.offine);
            //Console.WriteLine("QQ离开枚举成员的值：" + (int)QQSta te.leave);
            //Console.WriteLine("QQ忙碌枚举成员的值：" + (int)QQState.busy);
            //Console.WriteLine("QQ无聊枚举成员的值：" + (int)QQState.Qme);

            #endregion


            #region 将Int转换成枚举类型
            int n1 = 5;
            int n2 = 4;

            var state1 = (QQState)n1;
            var state2 = (QQState)n2;
            Console.WriteLine("QQ状态:" + state1);
            Console.WriteLine("QQ状态:" + state2);
            #endregion

            #region 将字符串转换成枚举类型
            string s = "其他";
            //将“其他”转换成 Gender其他
            //字符串类型转换成枚举类型
            Gender g = (Gender)Enum.Parse(typeof(Gender),s);
            Console.WriteLine(g);
            Console.WriteLine((int)g);//如果没定于整形将默认上往下0，1，2赋值
            #endregion
        }
    }
}
